package com.xiaolin.admin.controller;

import com.github.pagehelper.PageInfo;
import com.xiaolin.admin.annotations.HasApi;
import com.xiaolin.admin.constants.ApiPermConstant;
import com.xiaolin.admin.model.entity.SysPost;
import com.xiaolin.admin.service.SysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/12
 */
@Api("岗位资源")
@RestController
@RequestMapping("/post")
public class SysPostController {

    @Autowired
    private SysPostService postService;

    @HasApi(ApiPermConstant.COMMON_PERM)
    @ApiOperation("获取所有岗位")
    @PostMapping("/getList")
    public List<SysPost> getPostList(@RequestBody SysPost post) {
        return postService.getPostList(post);
    }

    @HasApi({"post:home"})
    @ApiOperation("获取岗位列表")
    @PostMapping("/getPage/{page}/{pageSize}")
    public PageInfo<SysPost> getPostPage(@PathVariable Integer page,
                                         @PathVariable Integer pageSize,
                                         @RequestBody SysPost post) {
        return postService.getPostPage(page, pageSize, post);
    }

    @HasApi({"post:add"})
    @ApiOperation("添加岗位")
    @PostMapping("/add")
    public boolean addPost(@RequestBody SysPost post) {
        return postService.addPost(post);
    }

    @HasApi({"post:get"})
    @ApiOperation("获取岗位")
    @PostMapping("/get/{id}")
    public SysPost getPost(@PathVariable("id") Integer id) {
        return postService.getPost(id);
    }

    @HasApi({"post:update"})
    @ApiOperation("修改岗位")
    @PostMapping("/update")
    public boolean updatePost(@RequestBody SysPost post) {
        return postService.updatePost(post);
    }

    @HasApi({"post:del"})
    @ApiOperation("删除岗位")
    @PostMapping("/delete/{id}")
    public boolean deletePost(@PathVariable Integer id) {
        return postService.deletePost(id);
    }
}
